/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.web.misc.jms;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.core.JmsTemplate;
import org.vacoor.nothing.common.util.Threads;

import javax.jms.*;
import java.util.concurrent.TimeUnit;

/**
 * @author vacoor
 */
public class IndexMessageListener implements MessageListener {
    private static final Logger LOG = LoggerFactory.getLogger(IndexMessageListener.class);
    private JmsTemplate jmsTemplate;
    private Destination notifyTopic;

    @Override
    public void onMessage(Message message) {
        TextMessage msg = (TextMessage) message;
        try {
            String text = msg.getText();
            LOG.info("start update index for: {}", text);
            Threads.sleep(5, TimeUnit.SECONDS);
            jmsTemplate.convertAndSend(notifyTopic, "failed:text");
        } catch (JMSException e) {
            LOG.debug("jms exception: {}", e);
        }
    }
}
